/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.game.config;

import java.awt.DisplayMode;

/**
 * This class decorates a DisplayMode to implement sort and toString()
 * It is intended to and ease integration with a combobox.
 * This class is immutable
 */
class CfgDisplayMode implements Comparable<CfgDisplayMode> {

    public String getLabel() {
        return label;
    }

    public DisplayMode getMode() {
        return mode;
    }
    private final DisplayMode mode;
    private final String label;

    public CfgDisplayMode(DisplayMode mode) {
        if(mode==null)
            throw new IllegalArgumentException();
        this.mode = mode;
        this.label = "" + mode.getWidth() + "x" + mode.getHeight() + " " + mode.getBitDepth() + "bit " + mode.getRefreshRate();
    }

    @Override
    public String toString() {
        return label;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CfgDisplayMode other = (CfgDisplayMode) obj;
        if (mode.getWidth()!=other.mode.getWidth()) {
            return false;
        }
        if (mode.getHeight()!=other.mode.getHeight()) {
            return false;
        }
        if (mode.getBitDepth()!=other.mode.getBitDepth()) {
            return false;
        }
        if (mode.getRefreshRate()!=other.mode.getRefreshRate()) {
            return false;
        }
        return true;
    }

   
    public int compareTo(CfgDisplayMode o) {
        if (mode.getWidth() != o.mode.getWidth()) {
            return o.mode.getWidth() - mode.getWidth();
        }
        if (mode.getHeight() != o.mode.getHeight()) {
            return o.mode.getHeight() - mode.getHeight();
        }
        if (mode.getBitDepth() != o.mode.getBitDepth()) {
            return o.mode.getBitDepth() - mode.getBitDepth();
        }
        return o.mode.getRefreshRate() - mode.getRefreshRate();
    }
}
